package com.rising.face.ali.bishi.findnumber;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: rising
 * @Description:
 * 题目：找到一个无序数组中找两个特定数，使其相加等于特定数字，请写代码java将它找出来，并指出时间复杂度。 例如
 * 【10,25,19,89,75,56,34,54,16，9，-5】找到相加等于28的【19，9 】
 * @Date: create in 2021/2/7 18:30
 */
public class FindNumber {
    public String findNum(int[] arrays, int target) {
        Map<Integer, Integer> sourceMap = new HashMap<>(arrays.length);
        for (int i = 0; i < arrays.length; i++) {
            sourceMap.put(arrays[i], arrays[i]);
        }

        for (int i = 0; i < arrays.length; i++) {
            int one = arrays[i];
            int two = target - arrays[i];
            if (sourceMap.get(two) != null) {
                return one + " + " + two + " = " + target;
            }
        }
        return "";
    }

    public static void main(String[] args) {
        int[] arrays = {10,25,19,89,75,56,34,54,16,9,-5};
        System.out.println(new FindNumber().findNum(arrays, 35));
    }
}
